﻿<?php 

require '../frame/base.php';
include("func/request.php");

$uid = !empty($_REQUEST['uid'])?$_REQUEST['uid']:null;
$sid = !empty($_REQUEST['sid'])?$_REQUEST['sid']:null;

if($uid){
	$users=$Db->table('user')->where('userid',$uid)->find();
	$url = "http://www.ewangpf.com/api/rongcloud/API/haha.php?uid=uid-".$users['userid']."&uname=".$users['niname']."&headimg=".$users['images'];
	$result = decodes2($url);
	if(!$result){
		 echo json_encode(['code'=>-100,'msg'=>'失败']);
		 exit;
	}

	$w = ['pw_token'=>$result['token']];
	if( $Db->table('user')->where('userid',$uid)->update($w) ){
		 echo json_encode(['code'=>200,'msg'=>'成功','data'=>$result['token']]);
	}else{
		 echo json_encode(['code'=>-100,'msg'=>'失败,用户不存在']);
	}
}

if($sid){
	$shops=$Db->table('shop')->where('shopid',$sid)->find();
	$url = "http://www.ewangpf.com/api/rongcloud/API/haha.php?uid=sid-".$shops['shopid']."&uname=".$shops['name']."&headimg=".$shops['head_pic'];
	$result = decodes2($url);
	if(!$result){
		 echo json_encode(['code'=>-100,'msg'=>'失败']);
		 exit;
	}

	$w = ['pw_token'=>$result['token']];
	if ( $Db->table('shop')->where('shopid',$sid)->update($w) ) {
		 echo json_encode(['code'=>200,'msg'=>'成功','data'=>$result['token']]);
	}else{
		 echo json_encode(['code'=>-100,'msg'=>'失败,厂商不存在']);
	}
}

